#ifndef SUBSCRIBER_H
#define SUBSCRIBER_H

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <chrono>

#define DEFAULT_RATE 200

typedef std::chrono::high_resolution_clock HighResClock;
typedef std::chrono::high_resolution_clock::time_point TimePoint;

struct ClientInfo
{
    int rate;           // 更新的条件：更新时间-上次发送时间>rate
    TimePoint sendTime; // 上次发送时间
    ClientInfo(int rt = DEFAULT_RATE, TimePoint time = HighResClock::now()) : rate(rt), sendTime(time) {}
};

class CSubscriberInfo
{
public:
    CSubscriberInfo();
    ~CSubscriberInfo();

    std::string getTopicName();
    void setTopicName(const std::string &topic);

    std::map<int, ClientInfo> getClientMap();
    std::vector<int> getClientIdList();
    void clientIdAdd(const int id);
    void clientIdAdd(const int id, const int rate);
    void clientIdRemove(const int id);
    void clientMapClear();

    int getSendRate(const int id);
    void setSendRate(const int id, const int rate);

    TimePoint getSendTime(const int id);
    void setSendTime(const int id, const TimePoint time);

private:
    std::string m_topic;
    std::map<int, ClientInfo> m_clientMap; // id 和 客户端在该条订阅下的信息

    void init();
};

#endif